package com.example.adapters;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import com.example.R;
import com.example.models.enteties.Topic;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: dlernatovich
 * Date: 6/27/12
 * Time: 12:44 PM
 * To change this template use File | Settings | File Templates.
 */
public class TopicAdapter extends ArrayAdapter<Topic> {

    private final Activity context;
    private final List<Topic> values;


    static class ViewHolder {
        public TextView title;
        public TextView describe;
    }

    public TopicAdapter(Activity context, int textViewResourceId, List<Topic> objects) {
        super(context, textViewResourceId, objects);
        this.context = context;
        this.values = objects;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        View rowView = convertView;
        if (rowView == null) {
            LayoutInflater inflater = context.getLayoutInflater();
            rowView = inflater.inflate(R.layout.topics_element, null);
            ViewHolder viewHolder = new ViewHolder();
            viewHolder.title = (TextView) rowView.findViewById(R.id.topicsTitle);
            viewHolder.describe = (TextView) rowView.findViewById(R.id.describeTitle);
            rowView.setTag(viewHolder);
        }

        ViewHolder holder = (ViewHolder) rowView.getTag();
        Topic s = values.get(position);
        holder.title.setText(s.getName());
        holder.describe.setText(s.getDescription());

        return rowView;
    }

}
